package org.artifact.builder.design;

import java.util.ArrayList;
import java.util.List;

import org.artifact.core.exception.ArtifactExceptionUtil;
import org.w3c.dom.Element;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
public class DesignIndex {
	private List<DesignColumn> columns = new ArrayList<>();
	private boolean unique;
	
	public DesignIndex(DesignTable table,Element element) {
		this.unique = Boolean.valueOf(element.getAttribute("unique"));
		
		String[] columnArray = StrUtil.split(element.getAttribute("columns"), ",");
		for (String column : columnArray) {
			DesignColumn designColumn = table.getByName(column);
			ArtifactExceptionUtil.isTrue(-1, "the table not find column", designColumn==null);
			columns.add(designColumn);
		}
	}
}
